#include "stdafx.h"
#include "ServerHandler.h"
#include "TypingDlg.h"


ServerHandler::ServerHandler()
{
}


ServerHandler::~ServerHandler()
{
}

EnHandleResult ServerHandler::OnAccept(ITcpServer * pSender, CONNID dwConnID, UINT_PTR soClient)
{
	return HR_OK;
}

EnHandleResult ServerHandler::OnReceive(ITcpServer * pSender, CONNID dwConnID, const BYTE * pData, int iLength)
{
	char str[64];
	memset(str, 0, sizeof(char) * 64);
	memcpy(str, pData, iLength);
	CString cs(str);
	CTypingDlg* dlg = (CTypingDlg*)pDlg;
	int index = cs.Find(_T("\r\n"));
	cs = cs.Left(index + 2);
	if (cs.Compare(_T("typing:join\r\n")) == 0) {
		dlg->handleJoin(dwConnID);
	}
	else if (cs.Left(19).Compare(_T("typing:client-steps")) == 0) {
		CString temp = cs.Right(cs.GetLength() - 20);
		CString val = temp.Left(temp.GetLength() - 2);
		dlg->m_nEnemySteps = _ttof(val);
	}

	return HR_OK;
}

EnHandleResult ServerHandler::OnClose(ITcpServer * pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
	return HR_OK;
}
